package cn.pw.test.com.news.adapter;

import android.content.res.Resources;
import android.widget.ImageView;
import android.widget.RatingBar;

import com.aries.ui.view.radius.RadiusTextView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import cn.pw.test.com.news.R;
import cn.pw.test.com.news.bean.CalendarBean;
import tech.com.commoncore.utils.FlagSwitchUtil;

public class CalendarAdapter extends BaseQuickAdapter<CalendarBean, BaseViewHolder> {

    public CalendarAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, CalendarBean item) {
        helper.setText(R.id.calendar_item_time_tx, item.predicttime);
        helper.setText(R.id.calendar_item_title_tx, item.title);
        helper.setText(R.id.calendar_item_city_tx, item.country);
        helper.setText(R.id.calendar_item_importance_tx, item.effect);
        helper.setText(R.id.calendar_item_previous_tx, "前值: " + (item.previous == null ? "未公布" : item.previous));
        helper.setText(R.id.calendar_item_reality_tx, "公布: " + (item.reality == null ? "未公布" : item.reality));
        helper.setText(R.id.calendar_item_forecast_tx, "预期: " + (item.forecast == null ? "未公布" : item.forecast));

        RatingBar ratingBar = helper.itemView.findViewById(R.id.calendar_item_rating_bar);
        ratingBar.setRating(item.importance);

        RadiusTextView importanceTx = helper.itemView.findViewById(R.id.calendar_item_importance_tx);
        Resources res = mContext.getResources();

        ImageView flagImg = helper.itemView.findViewById(R.id.calendar_item_flag_img);

        flagImg.setImageResource(FlagSwitchUtil.getFlagId(item.country));

        if (item.importance == 0 || item.importance == 1) {
            importanceTx.getDelegate().setBackgroundColor(res.getColor(R.color.news_color_importance_1));
        }
        if (item.importance == 2) {
            importanceTx.getDelegate().setBackgroundColor(res.getColor(R.color.news_color_importance_2));
        }
        if (item.importance == 3) {
            importanceTx.getDelegate().setBackgroundColor(res.getColor(R.color.news_color_importance_3));
        }
        if (item.importance == 4) {
            importanceTx.getDelegate().setBackgroundColor(res.getColor(R.color.news_color_importance_4));
        }
        if (item.importance >= 5) {
            importanceTx.getDelegate().setBackgroundColor(res.getColor(R.color.news_color_importance_5));
        }
    }
}
